<template>
  <el-table
    ref="multipleTable"
    :data="currentPageRecords"
    style="width: 100%"
    :header-cell-style="{ background: '#f3f6fb', border: '0' }"
    :header-row-style="{ border: '0' }"
    :row-style="{ height: '30px' }"
    :cell-style="{ padding: '4px', border: '0' }"
  >
    <el-table-column type="index" label="序号" width="100"> </el-table-column>
    <el-table-column prop="innerCode" label="设备编号" width="160">
    </el-table-column>
    <el-table-column prop="type.name" label="设备型号" width="160">
    </el-table-column>
    <el-table-column prop="node.name" label="详细地址" show-overflow-tooltip width="280">
    </el-table-column>
    <el-table-column
      :formatter="VmStatus"
      prop="vmStatus"
      label="设备状态"
      show-overflow-tooltip
      width="160"
    >
    </el-table-column>
    <el-table-column prop="ownerName" label="运营状态" show-overflow-tooltip width="300">
      <template v-slot="{ row }">
        <div class="status">
           <div class="item" :class="{ active: !item }" v-for="(item,index) in row.status" :key="index">{{ deviceStatus(index) }}</div>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="操作" show-overflow-tooltip>
      <template #default="{ row }">
        <el-button type="default" @click="$emit('lookStateInfo', row)"
          >查看详情</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import DeviceStateEnum from '@/constant/device-state'
import DeviceManagerEnum from '@/constant/device-manager'
export default {
  name: 'DeviceStateTable',
  props: {
    currentPageRecords: {
      type: Array,
      required: true
    }
  },
  data () {
    return {

    }
  },
  methods: {
    // 计算设备状态
    VmStatus (row, column, cellValue, index) {
      const item = DeviceManagerEnum.DeviceManager.find(
        item => item.id === cellValue
      )
      return item ? item.value : '未投放'
    },
    // 运营状态
    deviceStatus (name) {
      const item = DeviceStateEnum.DeviceState.find(item => item.id === name)
      return item.value
    }
  }
}
</script>

<style lang="scss" scoped>
  .el-table::before {
    height: 0;
  }
  .el-tooltip {
    .el-button--default {
      padding: 12px 0;
      border: 0;
      background-color: transparent;
      margin-right: 10px;
      color: #5f84ff;
    }
  }
  .active{
        background: #ff665f linear-gradient(135deg,#ffb043,#ffc020) !important;
  }
  .status {
    display: flex;
    .item {
      height: 23px;
      padding: 0 12px;
      background: #ff665f linear-gradient(135deg, #3fc997, #4bda98);
      border-radius: 14px;
      text-align: center;
      color: #fff;
      line-height: 23px;
      margin-right: 10px;
    }
  }
</style>
